package com.fuxi.cloud.desreport.service.a;

import com.alibaba.fastjson.JSONArray;
import com.fuxi.cloud.desreport.dao.JimuReportDbFieldDao;
import com.fuxi.cloud.desreport.entity.JmReportDbField;
import com.fuxi.cloud.desreport.service.IJmReportDbFieldService;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.minidao.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * a
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
@Service("jmReportDbFieldServiceImpl")
public class f implements IJmReportDbFieldService {
    @Autowired
    private JimuReportDbFieldDao dbFieldDao;

    public f() {
    }

    @Override
    public List<JmReportDbField> getByDbId(String id) {
        List var2 = this.dbFieldDao.listByDbId(id);
        return var2;
    }

    @Override
    public void deleteFieldByIds(JSONArray deleteIds) {
        if (deleteIds != null && deleteIds.size() != 0) {
            String var2 = "";

            for(int var3 = 0; var3 < deleteIds.size(); ++var3) {
                var2 = var2 + deleteIds.getString(var3) + ",";
            }

            if (!"".equals(var2)) {
                var2 = var2.substring(0, var2.lastIndexOf(","));
            }

            this.dbFieldDao.deleteBatchIds(Arrays.asList(var2.split(",")));
        }
    }

    @Override
    public void saveOrUpdateBatch(List<JmReportDbField> fieldList) {
        Iterator var2 = fieldList.iterator();

        while(var2.hasNext()) {
            JmReportDbField var3 = (JmReportDbField)var2.next();
            if (StringUtils.isNotEmpty(var3.getId())) {
                JmReportDbField var4 = this.dbFieldDao.get(var3.getId());
                if (null != var4) {
                    this.dbFieldDao.update(var3);
                } else {
                    this.dbFieldDao.insert(var3);
                }
            } else {
                var3.setId(String.valueOf(SnowflakeIdWorker.generateId()));
                this.dbFieldDao.insert(var3);
            }
        }

    }

    @Override
    public void deleteByReportId(String reportId) {
        this.dbFieldDao.deleteByReportId(reportId);
    }

    @Override
    public void deleteByIds(String ids) {
        this.dbFieldDao.deleteBatchIds(Arrays.asList(ids.split(",")));
    }
}

